/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module batchflx.c - Functions for Batch Data Flex Record Maintenance |
   @end

$Log: /SoftPay/SPK2SIM/Source/Batch/batchflx.c $
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/

#include <project.h>

#ifdef BATCH_DEFINED

#define BATCHFLX_C

#include <aclconio.h>
#include <stdlib.h>
#include <stdio.h>
#include <ascii.h>
#include <errno.h>
#include <svc.h>
#include <dbmgr.h>
#include <string.h>
#include <message.h>
#include <aclstr.h>
#include <aclutil.h>
#include <VarRec.h>

/** /#define DEBUG_BATCHFUN*/
#ifdef DEBUG_BATCHFUN
#define DEBUG_95
#endif

#include <define.h>
#include <transact.h>
#include <tran.h>
#include <util.h>
#include <mem.h>
#include <gds.h>
#include <msg.h>
#include <msgfuncs.h>
#include <msgclrk.h>
#include <msgshf.h>
#include <udt.h>
#include <cdt.h>
#include <cst.h>
#include <hdt.h>
#include <bdt.h>
#include <opt.h>
#include <tct.h>
#include <trt.h>
#include <sdt.h>
#include <udt.h>
#include <confio.h>
#include <form.h>
#include <revutl.h>
#include <test.h>
#include <spdebug.h>
#include <ui.h>
#include <entry.h>
#include <operate.h>
#include <pbatch.h>
#include <mdlfuncs.h>
#include <accum.h>
#include <table.h>
#include <funcids.h>
#include <autosttl.h>
#include <settle.h>
#include <settlbat.h>
#include <review.h>
#include <batmsg.h>
#include <mht.h>
#include <pfr.h>
#include <codesec.h>
#include <logo.h>
#include <mit.h>
#include <merch.h>
#include <multilng.h>
#include <oper.h>
#include <date.h>
#include <tblutil.h>

PFI_PUC_PBR BatchData_Store_Functions[] = {
    (PFI_PUC_PBR) NULL,
    inStoreRoomNum,
    inStoreCustNum,
    inStoreT1Data,
    inStoreT2Data,
    inStoreCHolder,

};

int inStoreOptionalBatchRecToFlexi(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int i,
    inRetVal = VS_SUCCESS;

    pdebug(("--inStoreBatchRecToFlexi--"));

    for (i = 1; i <= NO_OPTIONAL_BATCH_FIELDS; ++i) {
        if ((inRetVal = BatchData_Store_Functions[i] (pchTempMaxBatchRecFlexi, psrBRec)) != VS_SUCCESS)
            break;
    }

    if (inRetVal == VS_SUCCESS) {
    } else
        pdebug(("inRetVal=%d", inRetVal));

    return (inRetVal);
}

int inStoreRoomNum(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int inRetVal = VS_ERR;
    short shRetVal;

    pdebug(("--inStoreRoomNum--"));

    if (psrBRec->fRoomNum) {
        if ((shRetVal = shVarAddField(pchTempMaxBatchRecFlexi, BDS_ROOM_NUM, (unsigned char *) psrBRec->szRoomNum, ROOM_NUM_SIZE)) == VAR_NO_ERROR) {
            pdebug(("YEP"));
            inRetVal = VS_SUCCESS;
        }

        if (shRetVal == VAR_INSUFFICIENT_BUFFER_SPACE)
            inRetVal = (int) VAR_INSUFFICIENT_BUFFER_SPACE;
    } else {
        pdebug(("NOPE"));
        inRetVal = VS_SUCCESS;
    }

    return (inRetVal);
}

int inStoreCustNum(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int inRetVal = VS_ERR;
    short shRetVal;

    pdebug(("--inStoreCustNum--"));

    if (psrBRec->fCustNum) {
        if ((shRetVal = shVarAddField(pchTempMaxBatchRecFlexi, BDS_CUST_NUM, (unsigned char *) psrBRec->szCustNum, REF_CUST_SIZE)) == VAR_NO_ERROR) {
            pdebug(("YEP"));
            inRetVal = VS_SUCCESS;
        }

        if (shRetVal == VAR_INSUFFICIENT_BUFFER_SPACE)
            inRetVal = (int) VAR_INSUFFICIENT_BUFFER_SPACE;
    } else {
        pdebug(("NOPE"));
        inRetVal = VS_SUCCESS;
    }

    return (inRetVal);
}

int inStoreT1Data(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int inRetVal = VS_ERR;
    short shRetVal;

    pdebug(("--inStoreT1Data--"));

    if (psrBRec->fT1Data && fGetStoreTrack1()) {
        if ((shRetVal = shVarAddField(pchTempMaxBatchRecFlexi, BDS_T1_DATA, (unsigned char *) psrBRec->stT1Data, TRACK1_SIZE)) == VAR_NO_ERROR) {
            pdebug(("YEP"));
            inRetVal = VS_SUCCESS;
        }

        if (shRetVal == VAR_INSUFFICIENT_BUFFER_SPACE)
            inRetVal = (int) VAR_INSUFFICIENT_BUFFER_SPACE;
    } else {
        pdebug(("NOPE"));
        inRetVal = VS_SUCCESS;
    }

    return (inRetVal);
}

int inStoreT2Data(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int inRetVal = VS_ERR;
    short shRetVal;

    pdebug(("--inStoreT2Data--"));

    if (psrBRec->fT2Data && fGetStoreTrack2()) {
        if ((shRetVal = shVarAddField(pchTempMaxBatchRecFlexi, BDS_T2_DATA, (unsigned char *) psrBRec->stT2Data, TRACK2_SIZE)) == VAR_NO_ERROR) {
            pdebug(("YEP"));
            inRetVal = VS_SUCCESS;
        }

        if (shRetVal == VAR_INSUFFICIENT_BUFFER_SPACE)
            inRetVal = (int) VAR_INSUFFICIENT_BUFFER_SPACE;
    } else {
        pdebug(("NOPE"));
        inRetVal = VS_SUCCESS;
    }

    return (inRetVal);
}

int inStoreCHolder(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int inRetVal = VS_ERR;
    short shRetVal;

    pdebug(("--inStoreCHolder--"));

    if (psrBRec->fCHolder && fGetStoreCustName()) {
        if ((shRetVal = shVarAddField(pchTempMaxBatchRecFlexi, BDS_CHOLDER, (unsigned char *) psrBRec->szCHolder, CHOLDER_SIZE)) == VAR_NO_ERROR) {
            pdebug(("YEP"));
            inRetVal = VS_SUCCESS;
        }

        if (shRetVal == VAR_INSUFFICIENT_BUFFER_SPACE)
            inRetVal = (int) VAR_INSUFFICIENT_BUFFER_SPACE;
    } else {
        pdebug(("NOPE"));
        inRetVal = VS_SUCCESS;
    }

    return (inRetVal);
}

PFI_PUC_PBR BatchData_Load_Functions[] = {
    (PFI_PUC_PBR) NULL,
    inLoadRoomNum,
    inLoadCustNum,
    inLoadT1Data,
    inLoadT2Data,
    inLoadCHolder,

};

int inLoadOptionalBatchRecFromFlexi(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int i,
    inRetVal = VS_SUCCESS;

    for (i = 1; i <= NO_OPTIONAL_BATCH_FIELDS; ++i) {
        if ((inRetVal = BatchData_Load_Functions[i] (pchTempMaxBatchRecFlexi, psrBRec)) != VS_SUCCESS)
            break;
    }

    if (inRetVal == VS_SUCCESS) {
    }

    return (inRetVal);
}

int inLoadRoomNum(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int     inRetVal = VS_ERR,
    inLength;
    short shRetVal;

    pdebug(("--inLoadRoomNum--"));
    //jrd one source	
    #ifdef __arm
    if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_ROOM_NUM, (unsigned char *) &psrBRec->szRoomNum, ROOM_NUM_SIZE + 1, (unsigned short *) &inLength)) == VAR_NO_ERROR)
    #endif
    #ifdef _TARG_68000
    if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_ROOM_NUM, (unsigned char *) &psrBRec->szRoomNum, ROOM_NUM_SIZE + 1, (unsigned int *) &inLength)) == VAR_NO_ERROR)
    #endif	
	inRetVal = VS_SUCCESS;
    else if (shRetVal == VAR_FIELD_NOT_FOUND)
        inRetVal = VS_SUCCESS;

    return (inRetVal);
}

int inLoadCustNum(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int     inRetVal = VS_ERR,
    inLength;
    short shRetVal;

    pdebug(("--inLoadCustNum--"));
    //jrd one source
    #ifdef __arm
    if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_CUST_NUM, (unsigned char *) &psrBRec->szCustNum, REF_CUST_SIZE + 1, (unsigned short *) &inLength)) == VAR_NO_ERROR)
    #endif
    #ifdef _TARG_68000
    if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_CUST_NUM, (unsigned char *) &psrBRec->szCustNum, REF_CUST_SIZE + 1, (unsigned int *) &inLength)) == VAR_NO_ERROR)	
    #endif	
	inRetVal = VS_SUCCESS;
    else if (shRetVal == VAR_FIELD_NOT_FOUND)
        inRetVal = VS_SUCCESS;

    return (inRetVal);
}

int inLoadT1Data(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int     inRetVal = VS_ERR,
    inLength;
    short shRetVal;

    pdebug(("--inLoadT1Data--"));
    //jrd one source
    #ifdef __arm
    if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_T1_DATA, (unsigned char *) &psrBRec->stT1Data, TRACK1_SIZE + 1, (unsigned short *) &inLength)) == VAR_NO_ERROR)
    #endif
    #ifdef _TARG_68000
    if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_T1_DATA, (unsigned char *) &psrBRec->stT1Data, TRACK1_SIZE + 1, (unsigned int *) &inLength)) == VAR_NO_ERROR)
    #endif
	inRetVal = VS_SUCCESS;
    else if (shRetVal == VAR_FIELD_NOT_FOUND)
        inRetVal = VS_SUCCESS;

    return (inRetVal);
}

int inLoadT2Data(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int     inRetVal = VS_ERR,
    inLength;
    short shRetVal;

    pdebug(("--inLoadT2Data--"));
    //jrd one source	
    #ifdef __arm
    if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_T2_DATA, (unsigned char *) &psrBRec->stT2Data, TRACK2_SIZE + 1, (unsigned short *) &inLength)) == VAR_NO_ERROR)
    #endif
    #ifdef _TARG_68000
    if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_T2_DATA, (unsigned char *) &psrBRec->stT2Data, TRACK2_SIZE + 1, (unsigned int *) &inLength)) == VAR_NO_ERROR)
    #endif
	inRetVal = VS_SUCCESS;
    else if (shRetVal == VAR_FIELD_NOT_FOUND)
        inRetVal = VS_SUCCESS;

    return (inRetVal);
}

int inLoadCHolder(unsigned char* pchTempMaxBatchRecFlexi,BATCH_REC* psrBRec) {
    int     inRetVal = VS_ERR,
    inLength;
    short shRetVal;

    pdebug(("--inLoadCHolder--"));
     //jrd one source	
    #ifdef __arm
    if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_CHOLDER, (unsigned char *) &psrBRec->szCHolder, CHOLDER_SIZE + 1, (unsigned short *) &inLength)) == VAR_NO_ERROR)
    #endif
    #ifdef _TARG_68000
     if ((shRetVal = shVarGetField(pchTempMaxBatchRecFlexi, BDS_CHOLDER, (unsigned char *) &psrBRec->szCHolder, CHOLDER_SIZE + 1, (unsigned int *) &inLength)) == VAR_NO_ERROR)
    #endif
	inRetVal = VS_SUCCESS;
    else if (shRetVal == VAR_FIELD_NOT_FOUND)
        inRetVal = VS_SUCCESS;

    return (inRetVal);
}

int BATCHFLX_CODE_CHECK(char* a,char* b,short * c,char* d,unsigned char* e) {
    GET_VER(a, b, c, d, e);
    return 1;
}

#undef BATCHFLX_C

#endif // BATCHFLX_DEFINED
